package Component;

import org.json.JSONObject;

import Clock.Clock;
import Clock.IUpdate;
import GameObj.GameObject;
import Scene.Renderable;
import org.json.JSONException;
import com.badlogic.gdx.math.Rectangle;
public abstract class GameComponent implements IUpdate {
	final public static int E_GRAPHCOMPONENT = 1;
	final public static int E_PHYSICOMPONENT = 2;
	final public static int E_PACKAGECOMPONENT = 3;
	
	GameObject mHost = null;
	public float x;
	public float y;

	GameComponent mParent = null;
	
	protected boolean enable = true;

	public void SetHost(GameObject host) {
		mHost = host;
	}

	public GameObject GetHost() {
		return mHost;
	}
	

	public GameComponent GetParent()
	{
		return mParent;
	}
	
	public void SetParent(GameComponent parent)
	{
		mParent = parent;		
	}
	
	public void SetEnable(boolean bEnable)
	{
		enable = bEnable;		
	}

	public boolean GetEnable()
	{
		return enable;		
	}
	
	
	
	public boolean Load(JSONObject jsonComp)
	{
		boolean bResult = true;
		try
		{	 
			if(jsonComp.has("enable"))
			{
				enable = (jsonComp.getInt("enable") == 1);
			}
		}
		catch(JSONException e)
		{
			
		}
		
		return bResult;
	}
	

	final public static GameComponent createComponetByType(int nType,
			GameObject GO) {
		switch (nType) {
		case E_GRAPHCOMPONENT: {
			GraphComponent comp = new GraphComponent();
			comp.SetHost(GO);

			return comp;
		}
		case E_PHYSICOMPONENT: {
			PhysicComponent comp = new PhysicComponent();
			comp.SetHost(GO);
			return comp;
		}
		
		case E_PACKAGECOMPONENT: {
			ComponentPackage comp = new ComponentPackage();
			comp.SetHost(GO);
			return comp;
		}

		default:
			break;
		}
		return null;

	}


	abstract public int GetTypeId();
	
	public void Update(Clock clock)
	{
		if (!enable)
		{
			return;
		}
			
	
	}

}
